<template>
   <!-- 表格数据 -->
   <InnerPageTable ref="listTable" :config="pageTableConfig" height="280"></InnerPageTable>
</template>

<script>
import {submissionsColumns} from '../../js/quality-table'
   export default {
      props:{
         tableData:{
            type:Array,
            default:() => []
         },
         buName:{
            type:String,
            default:""
         }
      },
      data () {
         return {
            pageTableConfig: {
               loadDataFn: this.getTableList,
               columns: submissionsColumns.bind(this)(this.buName),
               autoFirst: false,
               border:true,
               isPage:false,
               initParam: {
                  "buName": "",
                  "totalFundScale": "",
                  "unReportFundScale": ""
               },
               allSelection: []
            },
            tableList:[],
            responseProcess:null
         }
      },

      methods: {
         getTableList({ responseProcess }) {
            this.responseProcess = responseProcess;
            if (this.tableList?.length) {
               if(this.tableList?.length < 5){
                  const len = this.tableList.length;
                  for(let i = len; i < 5;i++){
                     this.tableList.push({
						isEmpty:true,
                        buName:"",
                        totalFundScaleUnit:"",
                        unReportFundScaleUnit:""
                     })
                  }
               }
               this.tableList.forEach(ele => {
                  this.$set(ele, "totalFundScaleUnit", this.formatNumberWithUnit(ele.totalFundScale))
                  this.$set(ele, "unReportFundScaleUnit", this.formatNumberWithUnit(ele.unReportFundScale))
               })
            }
            const data = { records: this.tableList || [] }
            responseProcess(data);
         },

         sortMethod(type,value){
            if(this.tableList?.length){
               if(type == "desc"){
                  if(value == "totalFundScaleUnit"){
                     this.tableList.sort((i,j)=>{ return j.totalFundScale - i.totalFundScale})
                  }
                  else{
                     this.tableList.sort((i,j)=>{ return j.unReportFundScale - i.unReportFundScale})
                  }
               }
               else{
                  if(value == "totalFundScaleUnit"){
                     this.tableList.sort((i,j)=>{ return i.totalFundScale - j.totalFundScale})
                  }
                  else{
                     this.tableList.sort((i,j)=>{ return i.unReportFundScale - j.unReportFundScale})
                  }
               }
            }
         }
      },

      watch:{
         tableData:{
            handler(newVal) {
               this.tableList = JSON.parse(JSON.stringify(newVal || []));
               this.$refs.listTable.load();
            },
            deep: true
         }
      }
   }
</script>
<style lang="less" scoped>
  .app-container{
    display: flex;
    justify-content: space-between;
  }
  
</style>
